package ru.spbau.lifeincube.logic;

import java.util.ArrayList;
import java.util.List;

public class StateStorage {

    private int mStep = -1;

    private List<List<Cell>> mAddedItems;
    private List<List<Cell>> mRemovedItems;

    StateStorage(List<Cell> initItems) {
        mAddedItems = new ArrayList<>();
        mRemovedItems = new ArrayList<>();
        nextState(initItems, new ArrayList<Cell>());
    }

    public void nextState(List<Cell> added, List<Cell> removed) {
        mStep++;
        mAddedItems.add(added);
        mRemovedItems.add(removed);
    }

    public void toPrevState() {
        if (mStep > 0) {
            mRemovedItems.remove(mStep);
            mAddedItems.remove(mStep);
            mStep--;
        }
    }

    public int getSize() {
        return mStep;
    }

    public List<Cell> getPrevAdd() {
        return mAddedItems.get(mStep - 1);
    }

    public List<Cell> getPrevRemove() {
        return mRemovedItems.get(mStep - 1);
    }

    public List<Cell> getRemovedCells() {
        return mRemovedItems.get(mStep);
    }

    public List<Cell> getAddedCells() {
        return mAddedItems.get(mStep);
    }
}
